home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIZX.CPP < prev   
C/C++ Source or Header  |  1993-08-09  |  10KB  |  363 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zn.cpp
  5. //   Title:    Zinc Window Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_ZX.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_ZX
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_ZX::ZI_ZX(PCSZ _pcszZip4)
  57. : ZN_WINDOW("WIN_ZX", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_ZX::Initialize(CL_INIT_CLASS);
  60.     pcszZip4 = _pcszZip4;
  61.     Setup();
  62. }
  63.  
  64.  
  65. //----------------------------------------------------------------------------
  66. //   Description:    Destructor
  67. //    Parameters:
  68. //       Returns:    
  69. //----------------------------------------------------------------------------
  70. FN_M ZI_ZX::~ZI_ZX()
  71. {
  72.     ZI_ZX::Destroy(FALSE);
  73.     Terminate();
  74. }
  75.  
  76.  
  77. //----------------------------------------------------------------------------
  78. //   Description:    This function attempts to make a partial match to a state
  79. //                          name and place the virtual list selector on that state.
  80. //    Parameters:
  81. //       Returns:    TRUE if successful.
  82. //----------------------------------------------------------------------------
  83. VOID FN_M ZI_ZX::CheckMatch()
  84. {
  85.     PCSZ pcsz = GetString(FID(STR_SEARCH));
  86.     if (pcsz == NULL || !fInit)
  87.         return ;
  88.  
  89.     CHAR szWork[80];                            // Extract a 9 digit ZIP
  90.     PSZ psz1;
  91.     PCSZ psz2;
  92.  
  93.     psz1 = szWork;
  94.     psz2 = pcsz;
  95.     for (; psz2[0]; psz2++)
  96.         if (isascii(psz2[0]) && isdigit(psz2[0]))
  97.             *psz1++ = *psz2;
  98.     strcpy(psz1, "000000000");
  99.     szWork[MAX_ZIP4] = '\0';
  100.  
  101.     if (stricmp(szLastMatch, szWork) == 0)
  102.         return ;
  103.     strcpy(szLastMatch, szWork);
  104.                                                     // Search data file
  105.     if (!Z4_INQ::zx_file.First(Z4_INQ::zx, szLastMatch))
  106.         return ;
  107.     do                                                
  108.         {
  109.         CHAR szZip4[MAX_ZIP4+1];
  110.  
  111.         strcpy(szZip4, Z4_INQ::zx.szZip5);
  112.         strcat(szZip4, Z4_INQ::zx.szAddonLo);
  113.         if (strcmp(szZip4, szLastMatch) >= 0)
  114.             break;
  115.         }
  116.     while (Z4_INQ::zx_file.Next(Z4_INQ::zx));
  117.     SetVlistPos((LONG)Z4_INQ::zx_file.RecordNo());
  118.     SetCurrent(FID(STR_SEARCH));
  119.     return ;
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------------
  124. //   Description:    Display detail windows
  125. //    Parameters:
  126. //       Returns:    TRUE if successful.
  127. //----------------------------------------------------------------------------
  128. BOOL FN_M ZI_ZX::Detail()
  129. {
  130.     if (!Z4_INQ::zx_file.Record(Z4_INQ::zx, lCurrent))
  131.         return FALSE;
  132.     if (Z4_INQ::zx.cRecords)
  133.         {
  134.         PZI_Z4_LIST pzi_z4_list = new ZI_Z4_LIST(Z4_INQ::zx.cRecords, Z4_INQ::zx.arecid);
  135.        if (pzi_z4_list == NULL)
  136.           {
  137.           ErrorNoMem();
  138.             return FALSE;
  139.           }
  140.        else if (pzi_z4_list->IsValid())
  141.           pzi_z4_list->Show();
  142.         return TRUE;
  143.         }
  144.     if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, Z4_INQ::zx.arecid[0]))
  145.         return FALSE;
  146.     PZI_Z4_DETAIL pzi_z4_detail = new ZI_Z4_DETAIL(Z4_INQ::z4);
  147.     if (pzi_z4_detail == NULL)
  148.         return ErrorNoMem();
  149.     else if (pzi_z4_detail->IsValid())
  150.         pzi_z4_detail->Show();
  151.     return TRUE;
  152. }
  153.  
  154.  
  155. //----------------------------------------------------------------------------
  156. //   Description:    Destroy object. Free any resources used by object.
  157. //                          Normally called by destructor.
  158. //                        Should allow multiple calls from various classes.
  159. //                        A class should almost always re-init its variables when 
  160. //                        it is destroyed to prevent accidents.
  161. //    Parameters:    fDestroyAll        Destroy parents also?
  162. //                                            Default is TRUE.
  163. //       Returns:    TRUE if successful.
  164. //----------------------------------------------------------------------------
  165. BOOL FN_M ZI_ZX::Destroy(BOOL fDestroyAll)
  166. {
  167.     ZI_ZX::Initialize(CL_INIT_CLASS_VARS);
  168.     if (fDestroyAll)                            // Destroy parent.
  169.         ZI_ZX_PARENT::Destroy(fDestroyAll);
  170.     return TRUE;
  171. }
  172.  
  173.  
  174. //----------------------------------------------------------------------------
  175. //   Description:    Initialize object. 
  176. //                          Normally called by constructor.
  177. //                        Should allow multiple calls from various classes.
  178. //    Parameters:    sInit        Initialization code. May be one of the following:
  179. //                                        CL_INIT_CLASS            Reset class variables and
  180. //                                                                    and dynamic allocations for
  181. //                                                                    this class only.
  182. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  183. //                                                                    this class only.
  184. //                                        CL_INIT_VARS            Reset class variables for
  185. //                                                                    this class only.
  186. //                                        CL_INIT_ALL                Initialize class and all 
  187. //                                                                    parent class, including
  188. //                                                                    dynamic memory allocation.
  189. //                                    Default is CL_INIT_ALL
  190. //       Returns:    TRUE if successful.
  191. //----------------------------------------------------------------------------
  192. BOOL FN_M ZI_ZX::Initialize(SHORT sInit)
  193. {
  194.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  195.         ZI_ZX_PARENT::Initialize(sInit);
  196.  
  197.     szLastMatch[0] = '\0';
  198.     lCurrent = 0;
  199.     lRecords = 0;
  200.     fInit = FALSE;
  201.     pcszZip4 = NULL;
  202.     return TRUE;
  203. }
  204.  
  205.  
  206. //----------------------------------------------------------------------------
  207. //   Description:    
  208. //    Parameters:
  209. //       Returns:    TRUE if successful.
  210. //----------------------------------------------------------------------------
  211. BOOL FN_M ZI_ZX::Query(PZN_VLIST_ELEM pzn_vlist_elem)
  212. {
  213.     pzn_vlist_elem->pszBuf = szFormat;
  214.     szFormat[0] = '\0';
  215.  
  216.     if (!Z4_INQ::zx_file.Record(Z4_INQ::zx, pzn_vlist_elem->lId))
  217.         return FALSE;
  218.     if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, Z4_INQ::zx.arecid[0]))
  219.         return FALSE;
  220.  
  221.     CHAR szZip4Hi[MAX_ZIP4+10];
  222.     if (strcmp(Z4_INQ::z4.szAddonLo, Z4_INQ::z4.szAddonHi) != 0)
  223.         sprintf(szZip4Hi, "- %s-%s", Z4_INQ::z4.szZip5, Z4_INQ::z4.szAddonHi);
  224.     else
  225.         szZip4Hi[0] = '\0';
  226.  
  227.     CHAR szStreet[MAX_ADDR_LINE+2];
  228.     Z4_STANDARDIZE::Addr2Display(szStreet, Z4_INQ::z4);
  229.     sprintf(szFormat, "%c\t%s-%s\t%s\t%s",
  230.         (Z4_INQ::zx.cRecords > 1 ? '*': ' '),
  231.         Z4_INQ::z4.szZip5,
  232.         Z4_INQ::z4.szAddonLo,
  233.         szZip4Hi,
  234.         szStreet);
  235.  
  236.     return TRUE;
  237. }
  238.  
  239.  
  240. //----------------------------------------------------------------------------
  241. //   Description:
  242. //    Parameters:
  243. //       Returns:    TRUE if successful.
  244. //----------------------------------------------------------------------------
  245. BOOL FN_M ZI_ZX::Select()
  246. {
  247.     if (!Z4_INQ::zx_file.Record(Z4_INQ::zx, lCurrent))
  248.         return FALSE;
  249.     if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, Z4_INQ::zx.arecid[0]))
  250.         return FALSE;
  251.     CHAR szStreet[MAX_ADDR_LINE+2];
  252.     Z4_STANDARDIZE::Addr2Display(szStreet, Z4_INQ::z4);
  253.     SendMessage(ZiMainWindow(), ZI_MSG_ADDR, (PVOID)Z4_INQ::z4.szSecName, (PVOID)szStreet);
  254.     SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, NULL);
  255.     SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, NULL);
  256.     SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, (PVOID)Z4_INQ::z4.szZip5);
  257.     return TRUE;
  258. }
  259.  
  260.  
  261. //----------------------------------------------------------------------------
  262. //   Description:    Event monitor function.
  263. //    Parameters:    msg        Event code
  264. //                        pv1            Data pointer 1
  265. //                        pv2            Data pointer 2
  266. //       Returns:    Event code
  267. //----------------------------------------------------------------------------
  268. ZN_MSG FN_M ZI_ZX::User(ZN_MSG msg, PVOID, PVOID pv2)
  269. {
  270.     switch (msg)
  271.         {
  272.         case ZN_MSG_INIT:
  273.             fInit = TRUE;
  274.             if (pcszZip4)
  275.                 {
  276.                 SetString(FID(STR_SEARCH), pcszZip4);
  277.                 CheckMatch();
  278.                 }
  279.             return msg;
  280.  
  281.         case ZN_MSG_TERMINATE:
  282.             return msg;
  283.  
  284.         case ZN_MSG_VLIST_INIT:
  285.             {
  286. static int aiTabstops[] = { 2, 14, 32, 0, 0 };
  287.  
  288.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  289.             lRecords = Z4_INQ::zx_file.Records();
  290.             pzn_vlist_init->lElems = lRecords;
  291.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  292.             pzn_vlist_init->aiTabstops = aiTabstops;
  293.             }
  294.             return msg;
  295.  
  296.         case ZN_MSG_VLIST_TITLE:
  297.             {
  298.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  299.             pzn_vlist_elem->pszBuf = szFormat;
  300.             strcpy(szFormat, "\tZIP+4\t\tAddress");
  301.             }
  302.             return msg;
  303.         }
  304.     if (IsError())                                // Error condition
  305.         return msg;
  306.     switch (msg)
  307.         {
  308.         case ZN_MSG_STRING_CHANGE:
  309.             CheckMatch();
  310.             break;
  311.  
  312.         case ZN_MSG_VLIST_QUERY:
  313.             Query((PZN_VLIST_ELEM)pv2);
  314.             break;
  315.  
  316.         case ZN_MSG_VLIST_SELECT:
  317.             {
  318.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  319.             lCurrent = pzn_vlist_elem->lId;
  320.             }
  321.             // Fall through
  322.  
  323.         case ZN_MSG_VLIST_CURRENT:
  324.             {
  325.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  326.             LONG lRec = pzn_vlist_elem->lId;
  327.             sprintf(szFormat, "Record %ld of %ld", lRec + 1, lRecords);
  328.             SetHelp(szFormat);
  329.             }
  330.             break;
  331.  
  332.         case ZN_MSG_VLIST_DBL_CLK:
  333.             {
  334.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  335.             lCurrent = pzn_vlist_elem->lId;
  336.             }
  337.             // Fall through
  338.         case TB_DETAIL:
  339.             Detail();
  340.             break;
  341.  
  342.         case ZN_MSG_HELP:
  343.             return ZN_MSG_NO_HELP;
  344.  
  345.         case TB_CLOSE:
  346.             Close();
  347.             break;
  348.  
  349.         case TB_SELECT:
  350.             Select();
  351.             Close();
  352.             break;
  353.  
  354.         case TB_HELP:
  355.             NotDone();
  356.             break;
  357.         }
  358.     return msg;
  359. }
  360. //----------------------------------------------------------------------------
  361. //------------------------------- End of File --------------------------------
  362. //----------------------------------------------------------------------------
  363.